package com.pscsoft.lucene.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;


public class DateUtils {

    private DateUtils() {
    }

    private static SimpleDateFormat sdf;

    public static String date2String(Date d) {
        String pattern = "dd/MMM/yyyy:HH:mm:ss";
        sdf = new SimpleDateFormat(pattern, Locale.US);
        return sdf.format(d);
    }

    public static String date2String(Date d, String pattern) {
        sdf = new SimpleDateFormat(pattern, Locale.US);
        return sdf.format(d);
    }

    public static Date string2Date(String str) {
        String pattern = "dd/MMM/yyyy:HH:mm:ss";
        sdf = new SimpleDateFormat(pattern, Locale.US);
        try {
            return sdf.parse(str);
        } catch (ParseException e) {

            e.printStackTrace();
        }
        return null;
    }

    public static Date string2Date(String str, String pattern) {
        sdf = new SimpleDateFormat(pattern, Locale.US);
        try {
            return sdf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
